﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EpiPoker.DataAccess
{
    /// <summary>
    /// Stored Procedures for T_Table Table
    /// </summary>
    public class Table
    {
        #region UpdateDBB

        /// <summary>
        /// Create new table
        /// /// </summary>
        /// <returns>create a table</returns>
        public static bool CreateTable(T_Table table)
        {
            try
            {
                fbPokerEntities bdd = new fbPokerEntities();

                T_Category low_category = new T_Category();
                bdd.AddToT_Category(low_category);
                bdd.SaveChanges();

                table.idCategory = low_category.idCategory;
                table.DateOpened = DateTime.Now;
                bdd.AddToT_Table(table);
                bdd.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        #endregion

        #region GetFromDBB

        /// <summary>
        /// Complete table list
        /// </summary>
        /// <returns>list of tables else an empty table list</returns>
        public static List<T_Table> GetListTable()
        {
            try
            {
                fbPokerEntities bdd = new fbPokerEntities();
                return bdd.T_Table.ToList();
            }
            catch (Exception ex)
            {
                return new List<T_Table>();
            }
        }

        public static T_Table GetTable(long id)
        {
            try
            {
                fbPokerEntities bdd = new fbPokerEntities();
                return bdd.T_Table.Where(x => x.idTable == id).FirstOrDefault();
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        #endregion
    }
}